<script>
/**
 * 文件上传按钮
 *    props: { url: 上传地址,  el-upload: el-upload-props }
 *    @click() 上传完成钩子
 */
export default {
  name: 'YmFileButton',
  functional: true,
  render (h, context) {
    const { props = {}, listeners = {} } = context
    const label = props.label
    const success = (response) => {
      if (response.status !== false) {
        if (listeners.click) (listeners.click)()
      }
    }
    return h(
      'el-upload',
      {
        style: {
          float: 'left'
        },
        props: {
          action: props.url,
          'show-file-list': false,
          'on-success': success,
          ...(props.uploader || {})
        }
      },
      [
        h('el-button', {
          props
        }, label)
      ]
    )
  }
}
</script>
